package com.qiaoyanqing.ximalaya.discovermodule.discover_adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qiaoyanqing.ximalaya.R;
import com.qiaoyanqing.ximalaya.discovermodule.discover_entity.DiscoverRankSecondDataAnchorEntity;
import com.qiaoyanqing.ximalaya.util.MyLog;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 佳男 on 2016/12/7.
 */

public class DiscoverRankSecondAnchorAdapter extends BaseAdapter{
    private Context context;
    private List<DiscoverRankSecondDataAnchorEntity> list;
    private LayoutInflater inflater;
    private String url;

    public DiscoverRankSecondAnchorAdapter(Context context, List<DiscoverRankSecondDataAnchorEntity> list) {
        this.context = context;
        this.list = list;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final ViewHolder holder;
        if(view==null){
            view=inflater.inflate(R.layout.rank_second_item,viewGroup,false);
            holder=new ViewHolder(view);
            view.setTag(holder);

        }else{
            holder= (ViewHolder) view.getTag();
        }
        holder.index.setText(""+(i+1));
        holder.nickname.setText(list.get(i).getNickname());
        holder.personEdscribe.setText(list.get(i).getPersonDescribe());
        if (list.get(i).getFollowersCounts()>9999) {
            holder.followersCounts.setText((float)(list.get(i).getFollowersCounts()/10000)+"万");
        }else {
            holder.followersCounts.setText(list.get(i).getFollowersCounts()+"");
        }
        url=list.get(i).getLargeLogo();
        MyLog.i("AAAAAAAAAA",url);

        if(url!=null&&url.length()>0){
            Picasso.with(context)
                    .load(url)
                    .into(holder.icon);
        }

        return view;
    }
    public static class ViewHolder{
        TextView index;
        ImageView icon;
        TextView nickname;
        TextView personEdscribe;
        ImageView downloadIcon;
        CardView cardView;
        TextView followersCounts;
        public ViewHolder(View view){
            followersCounts=(TextView)view.findViewById(R.id.rank_second_text);
            cardView=(CardView)view.findViewById(R.id.rank_second_card);
            index=(TextView)view.findViewById(R.id.rank_second_index);
            icon=(ImageView)view.findViewById(R.id.rank_second_icon);
            nickname=(TextView)view.findViewById(R.id.rank_second_title);
            personEdscribe=(TextView)view.findViewById(R.id.rank_second_nickname);
            downloadIcon=(ImageView)view.findViewById(R.id.rank_second_download_icon);
        }
    }
}
